package be.HelloWeb.Web;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class HelloSevlet
 */
public class HelloServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
 
	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		SimpleDateFormat dateFormat =  new SimpleDateFormat("EEEEE dd MMMMM yyyy");
		SimpleDateFormat timeFormat =  new SimpleDateFormat("hh:mm:ss");
		
		Date now = new Date();
		
		String formattedDate = dateFormat.format(now);
		String formattedTime = timeFormat.format(now);
		
		String userName = request.getParameter("username");
		if (userName == null || userName.isEmpty()) userName = "World";
		
		PrintWriter out = response.getWriter();
		out.println("<html><head><title>HelloWeb</title></head>");
		out.println("<body><h1>Hello " + userName + "</h1>");
		out.println("<p>Nous sommes le " + formattedDate + "</p>");
		out.println("<p>Il est " + formattedTime + "</p>");
		out.println("</body></html>");
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doGet(request, response);
	}

}
